package com.cee.service.Impl;

import com.cee.dao.ShortAnswerMapper;
import com.cee.dto.ShortAnswerDTO;
import com.cee.model.ShortAnswer;
import com.cee.service.ShortAnswerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;


@Slf4j
@Service
@Transactional
public class ShortAnswerServiceImpl implements ShortAnswerService {

    @Autowired
    private ShortAnswerMapper shortAnswerMapper;

    @Override
    public int saveShortAnswer(ShortAnswer shortAnswer) throws Exception {
        return shortAnswerMapper.insert(shortAnswer);
    }

    @Override
    public List<ShortAnswerDTO> getShortAnswerList(ShortAnswerDTO shortAnswerDTO) {
        return shortAnswerMapper.getShortAnswerList(shortAnswerDTO);
    }

    @Override
    public void deleteShortAnswer(Integer id) {

        ShortAnswer shortAnswer = new ShortAnswer();
        shortAnswer.setId(id);
        shortAnswer.setDelDateTime(new Date());

        log.info("逻辑删除shortAnswer, id={}", id);
        shortAnswerMapper.updateShortAnswerById(shortAnswer);
    }

    @Override
    public List<ShortAnswerDTO> getListByExamId(Integer examId) {
        return shortAnswerMapper.getListByExamId(examId);
    }
}
